$(function() {
	
    //var client = new WindowsAzure.MobileServiceClient('https://sk8centraldes.azure-mobile.net/', 'EpNAeJhEEPvggfySYAorLTeMrPztlX95'), //HOMOLOGAÇÃO
	var client = new WindowsAzure.MobileServiceClient('https://sk8centralMS.azure-mobile.net/', 'BBMdYmogIqCvHwsklxslRGHOEOEdwx68'), //PRODUÇÃO
		spotItemTable = client.getTable('spot');
	
    // Read current data and rebuild UI.
    // If you plan to generate complex UIs like this, consider using a JavaScript templating library.
    function refreshSpotItems() {
        var query = spotItemTable;

        query.read().then(function(spotItems) {
            var listItems = $.map(spotItems, function(item) {
                return $('<li>')
                    .attr('data-spot-id', item.id)
                    .append($('<input class="item-id">').val(item.id))
					.append($('<input class="item-name">').val(item.name))
					.append($('<input class="item-latitude">').val(item.latitude))
                    .append($('<input class="item-longitude">').val(item.longitude))
                    .append($('<input class="item-address">').val(item.address))
					.append($('<input class="item-description">').val(item.description));
            });

            $('#spot-items').empty().append(listItems).toggle(listItems.length > 0);
            $('#summary').html('<strong>' + spotItems.length + '</strong> item(s)');
        }, handleError);
    }

    function handleError(error) {
        var text = error + (error.request ? ' - ' + error.request.status : '');
        $('#errorlog').append($('<li>').text(text));
    }

    function getTodoItemId(formElement) {
        return $(formElement).closest('li').attr('data-spot-id');
    }

   

    // On initial load, start by fetching the current data
    refreshSpotItems();
});
